/*
01-复杂度2 Maximum Subsequence Sum
*/
#include <stdio.h>

int main() {
    int n;
    int thisSum = 0, maxSum = 0;
    int tempFirst=-1,first=0, last=0; // 开始、结束位置
    int v;
    int v0; // 第0个数值
    int allNegative = 1; // 全是负数
    scanf("%d", &n);
    for (int i=0; i<n; i++) {
        scanf("%d", &v);
        if (i == 0) {
            // 记录第0个数值，若全为负数，需要输出这个值
            v0 = v;
        }
        if (v >= 0) {
            allNegative = 0;
        }
        thisSum += v;
        if (tempFirst == -1) {
            tempFirst = v;
        }
        if (thisSum > maxSum) {
            maxSum = thisSum;
            first = tempFirst;
            last = v;
        } else if (thisSum < 0) {
            thisSum = 0;
            tempFirst = -1;
        }
    }
    if (allNegative) {
        // f all the K numbers are negative, then its maximum sum is defined to be 0, 
        // and you are supposed to output the first and the last numbers of the whole sequence. 
        printf("0 %d %d\n", v0, v);
    } else {
        printf("%d %d %d\n", maxSum, first, last);
    }
    return 0;
}
